home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr47 / ucrasm27.zip / SOURCE.ZIP / RMV1ST.ASM < prev    next >
Assembly Source File  |  1992-03-10  |  3KB  |  148 lines

  1.  
  2. ; Need to include "lists.a" in order to get list structure definition.
  3.  
  4.         include    lists.a
  5.  
  6.  
  7. wp        equ    <word ptr>        ;I'm a lazy typist
  8.  
  9.  
  10. ; Special case to handle MASM 6.0 vs. all other assemblers:
  11. ; If not MASM 5.1 or MASM 6.0, set the version to 5.00:
  12.  
  13.         ifndef    @version
  14. @version    equ    500
  15.         endif
  16.  
  17.  
  18.  
  19. StdGrp        group    stdlib,stddata
  20. stddata        segment    para public 'sldata'
  21. stddata        ends
  22.  
  23. stdlib        segment    para public 'slcode'
  24.         assume    cs:stdgrp
  25.  
  26. ; sl_Remove1st -    ES:DI points at a list.
  27. ;            Removes the first item in the list and returns a
  28. ;            pointer to this item in DX:SI.  Returns the carry
  29. ;            flag set if the list was empty.
  30. ;
  31. ; Randall Hyde  3/3/92
  32. ;
  33.  
  34.         public    sl_Remove1st
  35. sl_Remove1st    proc    far
  36.         push    ds
  37.         push    es
  38.         push    di
  39.  
  40.         if    @version ge 600
  41.  
  42. ; MASM 6.0 version goes here
  43.  
  44.         cmp    wp es:[di].List.Head+2, 0    ;Empty list?
  45.         jne    HasAList
  46.  
  47. ; At this point, the Head pointer is zero.  This only occurs if the
  48. ; list is empty.
  49. ;
  50. ; Note: Technically, the NIL pointer is 32-bits of zero. However, this
  51. ; package assumes that if the segment is zero, the whole thing is zero.
  52. ; So don't put any nodes into segment zero!
  53.  
  54.         xor    dx, dx                ;Set DX:SI to NIL.
  55.         mov    si, dx
  56.         mov    wp es:[di].List.CurrentNode, dx    ;Set current node to
  57.         mov    wp es:[di].List.CurrentNode+2, dx  ; NIL.
  58.         stc
  59.         jmp    RemoveDone
  60.  
  61. ; If the HEAD pointer is NON-NIL, grab the guy off the front of the
  62. ; list down here.
  63.  
  64. HasAList:    mov    si, wp es:[di].List.Head      ;Get ptr to first
  65.         mov    ds, wp es:[di].List.Head+2    ; item
  66.  
  67. ; Remove the first node from the list by storing the first node's NEXT pointer
  68. ; into the list's HEAD pointer.  Check to see if the list becomes empty
  69. ; (because we'll need to adjust TAIL when that happens).
  70.  
  71.         mov    dx, wp ds:[si].Node.Next
  72.         mov    wp es:[di].List.Head, dx
  73.         mov    wp es:[di].List.CurrentNode, dx
  74.  
  75.         mov    dx, wp ds:[si].Node.Next+2
  76.         mov    wp es:[di].List.Head+2, dx
  77.         mov    wp es:[di].List.CurrentNode+2, dx
  78.  
  79.         or    dx, dx                ;List empty?
  80.         jnz     GoodRemove
  81.         mov    wp es:[di].List.Tail, dx
  82.         mov    wp es:[di].List.Tail+2, dx
  83.  
  84.  
  85.  
  86.  
  87.  
  88.  
  89.         else
  90.  
  91. ; All other assemblers come down here:
  92.  
  93.         cmp    wp es:[di].Head+2, 0        ;Empty list?
  94.         jne    HasAList
  95.  
  96. ; At this point, the Head pointer is zero.  This only occurs if the
  97. ; list is empty.
  98. ;
  99. ; Note: Technically, the NIL pointer is 32-bits of zero. However, this
  100. ; package assumes that if the segment is zero, the whole thing is zero.
  101. ; So don't put any nodes into segment zero!
  102.  
  103.         xor    dx, dx                ;Set DX:SI to NIL.
  104.         mov    si, dx
  105.         mov    wp es:[di].CurrentNode, dx
  106.         mov    wp es:[di].CurrentNode+2, dx
  107.         stc
  108.         jmp    RemoveDone
  109.  
  110. ; If the Tail pointer is non-NIL, append the new node to the end of the
  111. ; list down here.
  112.  
  113. HasAList:    mov    si, wp es:[di].Head          ;Get ptr to first
  114.         mov    ds, wp es:[di].Head+2        ; item
  115.  
  116. ; Remove the first node from the list by storing the first node's NEXT pointer
  117. ; into the list's HEAD pointer.  Check to see if the list becomes empty
  118. ; (because we'll need to adjust TAIL with that happens).
  119.  
  120.         mov    dx, wp ds:[si].Next
  121.         mov    wp es:[di].Head, dx
  122.         mov    wp es:[di].CurrentNode, dx
  123.  
  124.         mov    dx, wp ds:[si].Next+2
  125.         mov    wp es:[di].Head+2, dx
  126.         mov    wp es:[di].CurrentNode, dx
  127.  
  128.         or    dx, dx                ;List empty?
  129.         jnz     GoodRemove
  130.         mov    wp es:[di].Tail, dx
  131.         mov    wp es:[di].Tail+2, dx
  132.  
  133.  
  134.         endif
  135.  
  136. GoodRemove:    clc
  137.         mov    dx, ds
  138.  
  139. RemoveDone:    pop    di
  140.         pop    es
  141.         pop    ds
  142.         ret
  143.  
  144. sl_Remove1st    endp
  145.  
  146. stdlib        ends
  147.         end
  148.